package com.binvshe.binvshe.message;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.binvshe.binvshe.app.MyApplication;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/19
 */
public class EmHelper {
    /**
     * Created by Zoi
     * Method Name: LoginEM
     * Description: 登录环信
     */
    public static void LoginEM(String loginName, String password, final Activity activity) {
        EMClient.getInstance().login(loginName,password,new EMCallBack() {//回调
            @Override
            public void onSuccess() {
                EMClient.getInstance().groupManager().loadAllGroups();
                EMClient.getInstance().chatManager().loadAllConversations();
                Log.d("main", "登录聊天服务器成功！");
                activity.finish();
            }

            @Override
            public void onProgress(int progress, String status) {

            }

            @Override
            public void onError(int code, String message) {
                Toast.makeText(MyApplication.getAppContext(), "登录聊天服务器失败", Toast.LENGTH_SHORT).show();
            }
        });
    }

}
